//
//  LTHomeworkViewController.m
//  LearnTeacher
//
//  Created by zyl_macbookpro on 2024/4/18.
//

#import "LTHomeworkViewController.h"
#import "LTHomeworkAfterClassVC.h"
#import "LTHomeworkComputerExamVC.h"

@interface LTHomeworkViewController ()
@property(nonatomic ,strong)UIView *lineView;

@property(nonatomic ,strong)UIButton *selectedBtn;

@property(nonatomic ,strong)UIView *topBtnView;

@property(nonatomic ,strong)LTHomeworkAfterClassVC *homeworkAfter;

@property(nonatomic ,strong)LTHomeworkComputerExamVC *examVC;

@end

@implementation LTHomeworkViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
   
    [self renderNavBarWithBackgroundImage:[UIImage imageWithColor:rgba(74, 144, 246, 1)] backgroundColor:LTClearColor shadowColor:nil textAttributeDic:@{NSForegroundColorAttributeName:rgba(0, 0, 0, 1),NSFontAttributeName:MFontWithSize(17)} enableScrollEdgeAppearance:YES];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.titleView = self.topBtnView;
    [self setBackButtonIsHidden:YES];
}
- (void)chooseClick:(UIButton *)btn
{
    if (self.selectedBtn != btn) {
        self.selectedBtn = btn;
        [UIView animateWithDuration:0.3 animations:^{
            self.lineView.centerX = self.selectedBtn.centerX;
        }];
    }
    
}
- (UIView *)topBtnView
{
    if (!_topBtnView) {
        _topBtnView = [[UIView alloc] initWithFrame:CGRectMake(0,0, LTScreenWidth, 44)];
        _topBtnView.backgroundColor = LTClearColor;
        NSArray *title = @[@"听说模考",@"机房考试",@"课堂教学",@"打卡"];
        self.lineView.width = 16;
        for (int i = 0; i < title.count; i++) {
            UIButton *monthLBtn = ({
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake((LTScreenWidth - 80)/4.0*i ,2, ((LTScreenWidth - 80))/4.0, 42);
                [button setTitle:title[i] forState:UIControlStateNormal];
                [button setTitleColor:LTWhiteColor forState:UIControlStateNormal];
                [button addTarget:self action:@selector(chooseClick:) forControlEvents:UIControlEventTouchUpInside];
                button;
            });
            monthLBtn.titleLabel.font = RFontWithSize(13.f);
            monthLBtn.tag = i + 10000;
            if (i == 0) {
                self.selectedBtn = monthLBtn;
            }
            
            [_topBtnView addSubview:monthLBtn];
        }
        
        [_topBtnView addSubview: self.lineView];
        self.lineView.centerX = self.selectedBtn.centerX;
    }
    return _topBtnView;
}
- (UIView *)lineView
{
    if(!_lineView)
    {
        _lineView = [[UIView alloc] init];
        _lineView.frame = CGRectMake(95,36,28,3);
        _lineView.backgroundColor = LTWhiteColor;
        [_lineView setAllCornersWithCornerRadius:1.5];
    }
    return _lineView;
}
- (LTHomeworkAfterClassVC *)homeworkAfter
{
    if (!_homeworkAfter) {
        _homeworkAfter = [[LTHomeworkAfterClassVC alloc] init];
        _homeworkAfter.view.frame = CGRectMake(0, LTTopBarHeight, LTScreenWidth, LTScreenHeight - LTTopBarHeight - LTTabBarHeight - LTBottomDangerousAreaHeight);
        [self.view addSubview: _homeworkAfter.view];
        [self addChildViewController:_homeworkAfter];
    }
    return _homeworkAfter;
}
- (LTHomeworkComputerExamVC *)examVC
{
    if (!_examVC) {
        _examVC = [[LTHomeworkComputerExamVC alloc] init];
        _examVC.view.frame = CGRectMake(0, LTTopBarHeight, LTScreenWidth, LTScreenHeight - LTTopBarHeight - LTTabBarHeight - LTBottomDangerousAreaHeight);
        [self.view addSubview: _examVC.view];
        [self addChildViewController:_examVC];
    }
    return _examVC;
}
- (void)setSelectedBtn:(UIButton *)selectedBtn
{
    _selectedBtn.titleLabel.font = RFontWithSize(13.f);
    _selectedBtn = selectedBtn;
    _selectedBtn.titleLabel.font = SFontWithSize(16.f);
    self.homeworkAfter.view.hidden = YES;
    self.examVC.view.hidden = YES;
    if (self.selectedBtn.tag == 10000) {
        self.homeworkAfter.view.hidden = NO;
        [self.homeworkAfter refresh];
    }
    
    if (self.selectedBtn.tag == 10001) {
        self.examVC.view.hidden = NO;
        [self.examVC refresh];
    }
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
